/*
 *===============DdmgCloudPlatform3 V2.0===============
 * DdmgCloudPlatform3 V2.0
 * Copyright@大大买钢2018,All Rights Reserved
 * Author: XieZhuoxun(59296309@qq.com)
 * Date: 2018/8/21  08:43
 * TODO: 日期控件相关的选项
 *===============DdmgCloudPlatform3 V2.0===============
 */
import dayjs from "dayjs";

const datePickerOptions = {
  // 30天以外全部禁用
  thirtyDaysOption: {
    disabledDate(time) {
      const day = 24 * 3600 * 1000;
      const timestamp = time.getTime();
      return timestamp > (Date.now() - day);
    }
  },
  // 设置选择今天以及今天以前的日期  PS循环遍历，会有性能问题
  beforTodayOption: {
    // disabledDate(time) {
    //   return time.getTime() > Date.now() - 8.64e6;
    // },
  },
  // 设置选择今天以及今天以后的日期  PS循环遍历，会有性能问题
  afterTodayOption: {
    disabledDate(time) {
      return time.getTime() < Date.now() - 8.64e7;
    },
  },
  // 设置选择今天以前的日期（不包含今天）  PS循环遍历，会有性能问题
  beforExceptTodayOption: {
    disabledDate(time) {
      const today = new Date();
      return time.getTime() > new Date(today.getFullYear(), today.getMonth(), today.getDate() - 1, 0, 0, 0).getTime();
    },
  },
  // 设置选择今天以后的日期（不包含今天）  PS循环遍历，会有性能问题
  afterExceptTodayOption: {
    disabledDate(time) {
      const today = new Date();
      return time.getTime() < new Date(dayjs().getFullYear(), today.getMonth(), today.getDate() - 1, 0, 0, 0).getTime();
    },
  },
  getMonthFirstDay2Today: () => {
    return [
      dayjs()
        .startOf("month")
        .format("YYYY-MM-DD"),
      dayjs().format("YYYY-MM-DD"),
    ];
  },
  // 带快捷选项，设置选择今天以及今天以前的日期  PS循环遍历，会有性能问题
  pickerShutOptionsOne: {
    // disabledDate(time) {
    //   return time.getTime() > Date.now() - 8.64e6;
    // },
    shortcuts: [
      {
        text: "今天",
        onClick(picker) {
          const end = new Date();
          const start = new Date(new Date().toDateString());
          end.setTime(start.getTime());
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近一周",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近一个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "最近三个月",
        onClick(picker) {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        },
      },
    ],
  },
  // 带快捷选项，设置选择今天以及今天以后的日期  PS循环遍历，会有性能问题
  pickerShutOptionsTwo: {
    // disabledDate(time) {
    //   return time.getTime() > Date.now() - 8.64e6;
    // },
    shortcuts: [
      {
        text: "今天",
        onClick(picker) {
          const end = new Date();
          const start = new Date(new Date().toDateString());
          end.setTime(start.getTime());
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "往后一周",
        onClick(picker) {
          const start = new Date();
          const end = new Date();
          end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "往后一个月",
        onClick(picker) {
          const start = new Date();
          const end = new Date();
          end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
          picker.$emit("pick", [start, end]);
        },
      },
      {
        text: "往后三个月",
        onClick(picker) {
          const start = new Date();
          const end = new Date();
          end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
          picker.$emit("pick", [start, end]);
        },
      },
    ],
  },
};

export default datePickerOptions;
